﻿using AutoMapper;
using Volo.Abp.AutoMapper;

namespace CommonManagement
{
    /// <summary>
    /// 公共管理应用自动映射配置
    /// </summary>
    public class CommonManagementApplicationAutoMapperProfile : Profile
    {
        public CommonManagementApplicationAutoMapperProfile()
        {
            CreateMap<User, UserDto>()
                .ForMember(m => m.UserId, m => m.MapFrom(f => f.Id));
            CreateMap<Balance, BalanceDto>()
                .ForMember(m => m.UserName, m => m.MapFrom(f => f.User.UserName));
            CreateMap<Recharge, RechargeDto>()
                .ForMember(m => m.RechargeDate, m => m.MapFrom(f => f.RechargeDate.ToString("yyyy-MM-dd HH:mm:ss")))
                .ForMember(m => m.PayType, m => m.MapFrom(f => f.PayType.HasValue ? f.PayType.ToString() : string.Empty));


            CreateMap<Feedback, FeedbackDto>();
            CreateMap<Category, CategoryDto>();
            CreateMap<Comment, CommentDto>()
                .ForMember(m => m.UserName, m => m.MapFrom(f => f.User.UserName))
                .ForMember(m => m.NewsTitle, m => m.MapFrom(f => f.Press.Title));
            CreateMap<Press, PressDto>()
                .ForMember(m => m.Type, m => m.MapFrom(f => ((int)f.Type).ToString()))
                .ForMember(m => m.Top, m => m.MapFrom(f => f.Top.ToString()))
                .ForMember(m => m.Hot, m => m.MapFrom(f => f.Hot.ToString()))
                .ForMember(m => m.Status, m => m.MapFrom(f => f.Status.ToString()))
                .ForMember(m => m.PublishDate, m => m.MapFrom(f => f.PublishDate.ToString("yyyy-MM-dd")));


            CreateMap<Rotation, RotationDto>()
                .ForMember(m => m.Type, m => m.MapFrom(f => ((int)f.Type).ToString()));


            CreateMap<Province, ProvinceDto>();
            CreateMap<City, CityDto>()
                .ForMember(m => m.ProvinceName, m => m.MapFrom(f => f.Province.Name));
            CreateMap<Area, AreaDto>()
                .ForMember(m => m.CityName, m => m.MapFrom(f => f.City.Name))
                .ForMember(m => m.ProvinceName, m => m.MapFrom(f => f.City.Province.Name));
            CreateMap<Location, LocationDto>()
                .ForMember(m => m.Location, m => m.MapFrom(f => f.Name))
                .ForMember(m => m.Area, m => m.MapFrom(f => f.Area.Name))
                .ForMember(m => m.City, m => m.MapFrom(f => f.Area.City.Name))
                .ForMember(m => m.Province, m => m.MapFrom(f => f.Area.City.Province.Name));


            CreateMap<Service, ServiceDto>()
                .ForMember(m => m.ServiceType, m => m.MapFrom(f => f.Type))
                .ForMember(m => m.ServiceName, m => m.MapFrom(f => f.Name))
                .ForMember(m => m.ServiceDesc, m => m.MapFrom(f => f.Desc))
                .ForMember(m => m.IsRecommend, m => m.MapFrom(f => f.IsRecommend.ToString()));


            CreateMap<Product, ProductDto>();


            CreateMap<Score, ScoreDto>()
                .ForMember(m => m.Event, m => m.MapFrom(f => f.Event.ToString()))
                .ForMember(m => m.Score, m => m.MapFrom(f => f.score.ToString()))
                .ForMember(m => m.Type, m => m.MapFrom(f => f.Type.ToString()))
                .ForMember(m => m.ChangeDate, m => m.MapFrom(f => f.ChangeDate.ToString("yyyy-MM-dd HH:mm:ss")))
                .ForMember(m => m.UserName, m => m.MapFrom(f => f.User.UserName));
            CreateMap<Level, LevelDto>();
            CreateMap<Notice, NoticeDto>()
                .ForMember(m => m.Event, m => m.MapFrom(f => f.Event.ToString()))
                .ForMember(m => m.Score, m => m.MapFrom(f => f.Score.ToString()))
                .ForMember(m => m.Type, m => m.MapFrom(f => f.Type.ToString()))
                .ForMember(m => m.ChangeDate, m => m.MapFrom(f => f.ChangeDate.ToString("yyyy-MM-dd HH:mm:ss")))
                .ForMember(m => m.UserName, m => m.MapFrom(f => f.User.UserName));
            CreateMap<User, TopDto>()
                .ForMember(m => m.UserId, m => m.MapFrom(f => f.Id))
                .Ignore(m => m.DeptId)
                .Ignore(m => m.Salt)
                .Ignore(m => m.Status)
                .Ignore(m => m.DelFlag)
                .Ignore(m => m.LoginIp)
                .Ignore(m => m.LoginDate)
                .Ignore(m => m.Roles)
                .Ignore(m => m.RoleIds)
                .Ignore(m => m.PostIds)
                .Ignore(m => m.Admin);


            CreateMap<Order, OrderDto>()
                .ForMember(m => m.OrderNo, m => m.MapFrom(f => f.No))
                .ForMember(m => m.OrderStatus, m => m.MapFrom(f => f.Status.ToString()))
                .ForMember(m => m.PayTime, m => m.MapFrom(f => f.PayTime.HasValue ? f.PayTime.Value.ToString("yyyy-MM-dd") : null))
                .ForMember(m => m.OrderType, m => m.MapFrom(f => f.Type))
                .ForMember(m => m.OrderTypeName, m => m.MapFrom(f => f.TypeName));


            CreateMap<Weather, WeatherDto>()
                .ForMember(m => m.MaxTemperature, m => m.MapFrom(f => f.TempInfo.MaxTemperature))
                .ForMember(m => m.MinTemperature, m => m.MapFrom(f => f.TempInfo.MinTemperature))
                .ForMember(m => m.Temperature, m => m.MapFrom(f => f.TempInfo.Temperature))
                .ForMember(m => m.ApparentTemperature, m => m.MapFrom(f => f.TempInfo.ApparentTemperature))
                .ForMember(m => m.Weather, m => m.MapFrom(f => f.TempInfo.Weather))
                .ForMember(m => m.Humidity, m => m.MapFrom(f => f.TempInfo.Humidity))
                .ForMember(m => m.Uv, m => m.MapFrom(f => f.ComfortLevel.UvIndex))
                .ForMember(m => m.Air, m => m.MapFrom(f => f.AirQuantity.Air))
                .ForMember(m => m.Label, m => m.MapFrom(f => f.Label))
                .ForMember(m => m.Day, m => m.MapFrom(f => f.Day));
            CreateMap<Division, DivisionDto>();
            CreateMap<AirQuantity, AirQuantityDto>();
            CreateMap<ComfortLevel, ComfortLevelDto>();
            CreateMap<TempInfo, TempInfoDto>()
                .ForMember(m => m.MaxTemperature, m => m.MapFrom(f => f.MaxTemperature.ToString()))
                .ForMember(m => m.MinTemperature, m => m.MapFrom(f => f.MinTemperature.ToString()))
                .ForMember(m => m.Temperature, m => m.MapFrom(f => f.Temperature.ToString()))
                .ForMember(m => m.ApparentTemperature, m => m.MapFrom(f => f.ApparentTemperature.ToString()))
                .ForMember(m => m.Humidity, m => m.MapFrom(f => f.Humidity.ToString()));
            CreateMap<Wind, WindDto>();
            CreateMap<Weather, TodayDto>()
                .ForMember(m => m.Hours, m => m.MapFrom(f => f.Divisions));
        }
    }
}